package com.txts.road.admin.fenceSys.controller;

import com.txts.base.common.domain.PageResult;
import com.txts.base.common.domain.ResponseDTO;
import com.txts.road.admin.common.annotation.Log;
import com.txts.road.admin.common.core.controller.BaseController;
import com.txts.road.admin.common.core.domain.AjaxResult;
import com.txts.road.admin.common.core.page.TableDataInfo;
import com.txts.road.admin.common.enums.BusinessType;
import com.txts.road.admin.common.utils.poi.ExcelUtil;
import com.txts.road.admin.fenceSys.domain.FenceInfo;
import com.txts.road.admin.fenceSys.service.IFenceInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * 电子围栏信息Controller
 *
 * @author ruoyi
 * @date 2025-06-14
 */
@RestController
@RequestMapping("/fenceSys/fenceInfo")
@Tag(name = "电子围栏接口")
public class FenceInfoController extends BaseController {
    @Resource
    private IFenceInfoService fenceInfoService;

    /**
     * 查询电子围栏信息列表
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:list')")
    @GetMapping("/list")
    @Operation(summary = "查询电子围栏信息列表", description = "根据条件查询电子围栏信息列表")
    public ResponseDTO<PageResult<FenceInfo>> list(FenceInfo fenceInfo) {
        startPage();
        List<FenceInfo> list = fenceInfoService.selectFenceInfoList(fenceInfo);
        return getDataTable(list);
    }

    /**
     * 导出电子围栏信息列表
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:export')")
    @Log(title = "电子围栏信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出电子围栏信息列表", description = "导出电子围栏信息列表")
    public void export(HttpServletResponse response, FenceInfo fenceInfo) {
        List<FenceInfo> list = fenceInfoService.selectFenceInfoList(fenceInfo);
        ExcelUtil<FenceInfo> util = new ExcelUtil<FenceInfo>(FenceInfo.class);
        util.exportExcel(response, list, "电子围栏信息数据");
    }

    /**
     * 获取电子围栏信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:query')")
    @GetMapping(value = "/{fenceId}")
    @Operation(summary = "获取电子围栏信息详细信息", description = "根据围栏ID获取电子围栏信息详细信息")
     public ResponseDTO<Object> getInfo(@PathVariable("fenceId") Long fenceId) {
        return success(fenceInfoService.selectFenceInfoByFenceId(fenceId));
    }

    /**
     * 新增电子围栏信息
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:add')")
    @Log(title = "电子围栏信息", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增电子围栏信息", description = "新增电子围栏信息")
    public ResponseDTO<Object>add(@RequestBody FenceInfo fenceInfo) {
        return toAjax(fenceInfoService.insertFenceInfo(fenceInfo));
    }

    /**
     * 修改电子围栏信息
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:edit')")
    @Log(title = "电子围栏信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改电子围栏信息", description = "修改电子围栏信息")
    public ResponseDTO<Object>edit(@RequestBody FenceInfo fenceInfo) {
        return toAjax(fenceInfoService.updateFenceInfo(fenceInfo));
    }

    /**
     * 删除电子围栏信息
     */
    @PreAuthorize("@ss.hasPermi('fenceSys:fenceInfo:remove')")
    @Log(title = "电子围栏信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fenceIds}")
    @Operation(summary = "删除电子围栏信息", description = "删除电子围栏信息")
    public ResponseDTO<Object>remove(@PathVariable Long[] fenceIds) {
        return toAjax(fenceInfoService.deleteFenceInfoByFenceIds(fenceIds));
    }
}
